// pages/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:'',
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // wx.setNavigationBarColor({
    //   frontColor: '#ffffff',
    //   backgroundColor: '#ed5a65',
     
    // })
    console.log('首页onload')
   console.log(options)
  
    if(options.type == 'cartList'){
      var loginInfo=wx.getStorageSync('loginInfo');
      var time = new Date().getTime()
      var key = ""
      var username = ""
      var userid = ""
      if(loginInfo){
        key = loginInfo.userInfo.key
        username = loginInfo.userInfo.username
        userid = loginInfo.userInfo.userid
      }
      var src = `${getApp().globalData.webUrl}/wap/tmpl/cart_list.html?stamp=${time}&key=${key}&username=${username}&userid=${userid}`;
      console.log('地址')
      console.log(src)
      
      this.setData({
        url:src
      })
      }else if(options.type == 'member'){
        var loginInfo=wx.getStorageSync('loginInfo');
        var time = new Date().getTime()
        var key = ""
        var username = ""
        var userid = ""
        if(loginInfo){
          key = loginInfo.userInfo.key
          username = loginInfo.userInfo.username
          userid = loginInfo.userInfo.userid
        }
        var src = `${getApp().globalData.webUrl}/wap/tmpl/member/member.html?stamp=${time}&key=${key}&username=${username}&userid=${userid}`;
        this.setData({
          url:src
        })
        }else if(options.type == 'payment'){
        var loginInfo=wx.getStorageSync('loginInfo');
        var time = new Date().getTime()
        var key = ""
        var username = ""
        var userid = ""
        if(loginInfo){
          key = loginInfo.userInfo.key
          username = loginInfo.userInfo.username
          userid = loginInfo.userInfo.userid
        }
        var src = `${getApp().globalData.webUrl}/wap/tmpl/member/member.html?stamp=${time}&key=${key}&username=${username}&userid=${userid}`;
 
        this.setData({
          url:src
        })
      }else if(options.type == 'productDetail'){
        var loginInfo=wx.getStorageSync('loginInfo');
        var time = new Date().getTime()
        var key = ""
        var username = ""
        var userid = ""
        if(loginInfo){
          key = loginInfo.userInfo.key
          username = loginInfo.userInfo.username
          userid = loginInfo.userInfo.userid
        }
        var goodsId = options.goodsId
        
        var src = `${getApp().globalData.webUrl}/wap/tmpl/product_detail.html?goods_id=${goodsId}&stamp=${time}&key=${key}&username=${username}&userid=${userid}&from=saoma`;
        
        this.setData({
          url:src
        })
        console.log(goodsId,src)
      }else if(options.type == 'bangmai'){
        var loginInfo=wx.getStorageSync('loginInfo');
        var time = new Date().getTime()
        var key = ""
        var username = ""
        var userid = ""
        if(loginInfo){
          key = loginInfo.userInfo.key
          username = loginInfo.userInfo.username
          userid = loginInfo.userInfo.userid
        }
        var goodsId = options.goodsId
        
        var src = `${getApp().globalData.webUrl}/wap/tmpl/distribution/bangmai.html?goods_id=${goodsId}&dealer_member_id=${userid}&from=bangmai`;
        
        this.setData({
          url:src
        })
        console.log(goodsId,src)
      }else{
        this.getUrl()
      } 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  getUrl:function(){
    var loginInfo=wx.getStorageSync('loginInfo');
    var time = new Date().getTime()
    var key = ""
    var username = ""
    var userid = ''
    if(loginInfo){
      key = loginInfo.userInfo.key
      username = loginInfo.userInfo.username
      userid = loginInfo.userInfo.userid
    }
    var src = `${getApp().globalData.webUrl}/wap/?stamp=${time}&key=${key}&username=${username}&userid=${userid}`;
    console.log('登录后的链接');
    console.log(src);
    this.setData({
      url:src
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {
    
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      })
    }
   // this.getUrl()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  h5PostMessage:function(e){
    var length = e.detail.data.length -1 ;
    this.h5Data= [e.detail.data[length]] ; 
    // this.h5Data= e.detail.data ; 
    console.log(e.detail.data[length],"nnnnnn")
    console.log(length,this.h5Data)

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {
    console.log(this.h5Data,{
      title:this.h5Data[0].title,
      desc:this.h5Data[0].desc,
      path:this.h5Data[0].path
    })
    return {
      title:this.h5Data[0].title,
      desc:this.h5Data[0].desc,
      path:this.h5Data[0].path
    }
  }
})